/*
生產消費者模型，通過channel作爲緩衝區。
*/

package main

import "fmt"

type OrderInfo struct {
	id int
}

func producer2(out chan<- OrderInfo) {
	for i := 0; i < 10; i++ {
		order := OrderInfo{id: i + 1}
		out <- order
	}
	close(out)
}

func consumer2(in <-chan OrderInfo) {
	for order := range in {
		fmt.Println("訂單ID為：", order.id)
	}
}

func main() {
	order := make(chan OrderInfo, 6)
	go producer2(order) //子goroutine，寫入訂單號
	consumer2(order)    //主goroutine，讀取訂單號
}
